/*
 * SmsViewerController.java
 *
 * Created on January 7, 2009, 6:14 AM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package org.vacuela.publishmx.web.controllers;

import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.multiaction.MultiActionController;
import org.vacuela.publishmx.context.ServiceContext;
import org.vacuela.publishmx.context.ServiceContextImpl;
import org.vacuela.publishmx.domains.Message;
import org.vacuela.publishmx.services.MessagingService;
import org.vacuela.publishmx.util.PublishUtil;
import static org.vacuela.publishmx.constant.Constants.*;

/**
 *
 * @author nestor.carrasco
 */
public class SmsViewerController extends MultiActionController{
    private MessagingService msgSvc;
    
    public ModelAndView portletViewer(HttpServletRequest request, HttpServletResponse response){
        ModelAndView mav = new ModelAndView("viewer/portletViewer");
        ServiceContext context = new ServiceContextImpl();
        msgSvc.readNewInputMessages(context);
        List<Message> inpuMsgList = (List<Message>)context.getAttribute("inpuMsgList");
        
        mav.addObject("inpuMsgList", inpuMsgList);
        return mav;
    }
    
    public ModelAndView ignoreMessage(HttpServletRequest request, HttpServletResponse response){
        ServiceContext context = new ServiceContextImpl();
        String msgIds = PublishUtil.checkForNullOrEmpty(request.getParameter("msgIds"));      
        if ( !"".equals(msgIds) ){
            context.setAttribute("msgIds",msgIds);
            context.setAttribute("newStatus", IN_MSG_STATUS_IGNORED);            
            msgSvc.changeStatusOfMessage(context);
        }       
        
        return portletViewer(request, response);
    }
    public void setMessagingService(MessagingService svc){
        this.msgSvc = svc;
    }
}
